Aller au contenu principal

HACKTHEBOX - ROGUEONE

Contexte

Votre SIEM a généré plusieurs alertes en moins d'une minute, indiquant une potentielle communication C2 à partir du poste de travail de Simon Stark. Malgré le fait que Simon n'ait rien remarqué d'inhabituel, l'équipe informatique lui a demandé de partager des captures d'écran de son gestionnaire de tâches pour vérifier la présence de processus inhabituels. Aucun processus suspect n'a été trouvé, yet les alertes concernant des communications C2 ont persisté. Le responsable du SOC a alors ordonné le confinement immédiat du poste de travail et un dump mémoire pour analyse. En tant qu'expert en forensique mémoire, vous êtes chargé d'assister l'équipe du SOC chez Forela pour enquêter et résoudre cet incident urgent.

Contenu

1 zip de 1.3GB contenant un memory dump de 5.5 GB dans un format .mem. Ce dump semble provenir d'une machine windows

Analyse du contenu

Analysons les process en cours dans la machine avec volatility.

Volatility3

Volatility est un outil très utile en forensic pour analyser des dumps mémoire Linux et Windows. Pour ce writeup, nous allons utiliser la dernière version de volatility à ce jour, c'est a dire la version 3.

Cela veut dire que lorsque vol.py est mentionné, c'est en réalité l'executable correspondant à volatility3

Lien pour télécharger volatility3 : https://github.com/volatilityfoundation/volatility3

python3.11 vol.py -f ../20230810.mem windows.pstree.PsTree
PID	PPID	ImageFileName	Offset(V)	Threads	Handles	SessionId	Wow64	CreateTime	ExitTime

<SNIP>
** 7436 7400 explorer.exe 0x9e8b8c4d2080 75 - 1 False 2023-08-10 11:14:07.000000 N/A
*** 5864 7436 WinRAR.exe 0x9e8b92bdb0c0 5 - 1 False 2023-08-10 11:20:21.000000 N/A
**** 1576 5864 msedgewebview2 0x9e8b8b4cc080 47 - 1 False 2023-08-10 11:20:21.000000 N/A
***** 6084 1576 msedgewebview2 0x9e8b8b0f1080 19 - 1 False 2023-08-10 11:20:25.000000 N/A
***** 2728 1576 msedgewebview2 0x9e8b8cf97080 7 - 1 False 2023-08-10 11:20:21.000000 N/A
***** 2284 1576 msedgewebview2 0x9e8b8b8dc080 14 - 1 False 2023-08-10 11:20:25.000000 N/A
***** 1552 1576 msedgewebview2 0x9e8b8aa85080 8 - 1 False 2023-08-10 11:20:25.000000 N/A
***** 1616 1576 msedgewebview2 0x9e8b8a74f080 22 - 1 False 2023-08-10 11:20:25.000000 N/A
*** 936 7436 svchost.exe 0x9e8b8cd89080 0 - 1 False 2023-08-10 11:22:31.000000 2023-08-10 11:27:51.000000
**** 8260 936 cmd.exe 0x9e8b8afda300 2 - 1 False 2023-08-10 11:27:15.000000 N/A
***** 1668 8260 conhost.exe 0x9e8b92c65300 3 - 1 False 2023-08-10 11:27:15.000000 N/A
*** 9580 7436 SecurityHealth 0x9e8b90135340 1 - 1 False 2023-08-10 11:14:25.000000 N/A
*** 9712 7436 vmtoolsd.exe 0x9e8b8cbd5080 9 - 1 False 2023-08-10 11:14:26.000000 N/A
*** 2776 7436 RamCapture64.e 0x9e8b8aa66080 5 - 1 False 2023-08-10 11:31:52.000000 N/A
**** 9816 2776 conhost.exe 0x9e8b91cda080 6 - 1 False 2023-08-10 11:31:52.000000 N/A
*** 6812 7436 svchost.exe 0x9e8b87762080 3 - 1 False 2023-08-10 11:30:03.000000 N/A
**** 4364 6812 cmd.exe 0x9e8b8b6ef080 1 - 1 False 2023-08-10 11:30:57.000000 N/A
***** 9204 4364 conhost.exe 0x9e8b89ec7080 3 - 1 False 2023-08-10 11:30:57.000000 N/A

On remarque un process svchost.exe (PID 936 et PID 6812) qui ont comme process enfant cmd.exe. Cela semble suspicieux. Pour confirmer le doute, nous pouvons dumper l'historique des commandes exécutées sur la machine :

python3.11 vol.py -f ../20230810.mem windows.cmdline.CmdLine
6812	svchost.exe	"C:\Users\simon.stark\Downloads\svchost.exe"
4364 cmd.exe C:\WINDOWS\system32\cmd.exe
9204 conhost.exe \??\C:\WINDOWS\system32\conhost.exe 0x4
9784 SearchFilterHo "C:\WINDOWS\system32\SearchFilterHost.exe" 0 764 820 828 8192 824 808
2776 RamCapture64.e "C:\Users\simon.stark\Desktop\BelkaSoft Live RAM Capturer\BelkaSoft Live RAM Capturer\RamCapture64.exe"
9816 conhost.exe \??\C:\WINDOWS\system32\conhost.exe 0x4

On voit que l'emplacement du svchost.exe n'est pas "standard" (C:\Users\simon.stark\Downloads\svchost.exe). Il y a de fortes chances que ce dernier est un process malicieux, qui cherche a usurper le process authentique svchost.exe (https://en.wikipedia.org/wiki/Svchost.exe)

T1 : Please identify the malicious process and confirm process id of malicious process : 6812

T2 : The SOC team believe the malicious process may spawned another process which enabled threat actor to execute commands. What is the process ID of that child process : 4364

A noter que l'on remarque que l'autre process semble authentique. Son emplacement est standard (C:\WINDOWS\System32\svchost.exe) et correspond au service authentique :

9088	svchost.exe	C:\WINDOWS\System32\svchost.exe -k wsappx -p -s ClipSVC
6344 svchost.exe C:\WINDOWS\system32\svchost.exe -k defragsvc
1244 svchost.exe C:\WINDOWS\System32\svchost.exe -k LocalSystemNetworkRestricted -p -s DsSvc
8260 cmd.exe C:\WINDOWS\system32\cmd.exe
1668 conhost.exe \??\C:\WINDOWS\system32\conhost.exe 0x4

Nous pouvons alors dumper cet executable pour analyse. Pour ceci, nous devons d'abord "scanner" les fichiers du dump avec volatility pour trouver l'adresse virtuelle du fichier correspondant :

python3.11 vol.py -f ../20230810.mem windows.filescan.FileScan | grep 'svchost.exe'
<SNIP>
0x9e8b909045d0 \Users\simon.stark\Downloads\svchost.exe 216
</SNIP>

Maintenant que nous avons l'adresse virtuelle de l'executable nous pouvons le dumper :

python3.11 vol.py -o /home/victorhin0/HTB/SHERLOCKS/ROGUEONE -f ../20230810.mem windows.dumpfiles.DumpFiles --virtaddr 0x9e8b909045d0
Volatility 3 Framework 2.5.2
Progress: 100.00 PDB scanning finished
Cache FileObject FileName Result

DataSectionObject 0x9e8b909045d0 svchost.exe Error dumping file
ImageSectionObject 0x9e8b909045d0 svchost.exe file.0x9e8b909045d0.0x9e8b957f24c0.ImageSectionObject.svchost.exe.img

Le fichier .img est en réalité le svchost.exe

On peut calculer son md5 (notamment pour comparer avec une TI telle que VirusTotal)

md5sum svchost.exe
5bd547c6f5bfc4858fe62c8867acfbb5 svchost.exe

T3 : The reverse engineering team need the malicious file sample to analyze. Your SOC manager instructed you to find the hash of the file and then forward the sample to reverse engineering team. Whats the md5 hash of the malicious file? : 5bd547c6f5bfc4858fe62c8867acfbb5

Nous avons confirmé qu'il y a bien un process malicieux dans la machine dumpée. Nous devons alors identifier le serveur C2C (Command and Control). Pour cela nous allons lister les connexions effectuées dans la machine :

python3.11 vol.py -o /home/victorhin0/HTB/SHERLOCKS/ROGUEONE -f ../20230810.mem windows.netscan > ../netlist.txt

Nous avons alors un fichier texte avec la liste des connexions entrantes/sortantes établies, et les connexions "en attente" (type un serveur HTTP sans avoir de connexions actives). Nous pouvons filtrer les résultats pour correspondre au PID malicieux (ici 6812) :

cat ../netlist.txt | grep 6812
0x9e8b8cb58010 TCPv4 172.17.79.131 64254 13.127.155.166 8888 ESTABLISHED 6812 svchost.exe 2023-08-10 11:30:03.000000

On identifie alors que le serveur de C2C est 13.127.155.166 et le port utilisé est 8888

T4 : In order to find the scope of the incident, the SOC manager has deployed a threat hunting team to sweep across the environment for any indicator of compromise. It would be a great help to the team if you are able to confirm the C2 IP address and ports so our team can utilise these in their sweep. : 13.127.155.166:8888

T5 : We need a timeline to help us scope out the incident and help the wider DFIR team to perform root cause analysis. Can you confirm time the process was executed and C2 channel was established? 10/08/2023 11:30:03

Maintenant, nous allons relever l'offset memory du process malveillant. Pour cela, nous pouvons lister les process en cours dans la machine :

python3.11 vol.py -f ../20230810.mem windows.pslist.PsList | grep 6812
6812 7436 svchost.exe 0x9e8b87762080 3 - 1 False 2023-08-10 11:30:03.000000 N/A Disabled
4364 6812 cmd.exe 0x9e8b8b6ef080 1 - 1 False 2023-08-10 11:30:57.000000 N/A Disabled

T6 : What is the memory offset of the malicious process? : 0x9e8b87762080

Enfin, nous uploadons le md5 correspondant au fichier malicieux sur virustotal : https://www.virustotal.com/gui/file/eaf09578d6eca82501aa2b3fcef473c3795ea365a9b33a252e5dc712c62981ea/details

On remarque que le fichier est bien detecté par la majorité des moteurs AV. On relève la date de la première soumision

T7 : You successfully analyzed a memory dump and received praise from your manager. The following day, your manager requests an update on the malicious file. You check VirusTotal and find that the file has already been uploaded, likely by the reverse engineering team. Your task is to determine when the sample was first submitted to VirusTotal : 10/08/2023 11:58:10

Références utiles

https://andreafortuna.org/2017/07/10/volatility-my-own-cheatsheet-part-3-process-memory/

https://book.hacktricks.xyz/generic-methodologies-and-resources/basic-forensic-methodology/memory-dump-analysis/volatility-cheatsheet